package cn.tedu._05weibo.common.response;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

//    响应统一处理
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
//    状态码,提示消息,具体数据
    private Integer state;
    private String message;
    private Object data;

//    1.针对没有具体数据返回
    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getState();
        this.message=statusCode.getMessage();
    }

//    2.针对于有具体数据返回的
    public JsonResult(StatusCode statusCode, Object data){
        this.state=statusCode.getState();
        this.message=statusCode.getMessage();
        this.data=data;
    }

//    1.针对于有具体数据返回的静态方法
    public static JsonResult ok(Object data){
        return  new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }

//    2.针对于没有具体数据返回的静态
    public static JsonResult ok(){
        return ok(null);
    }

}
